package com.hnkywl.sts.action.base;

import com.hnkywl.sts.entity.base.Dxpz;
import com.hnkywl.sts.service.base.DxpzService;
import net.ruixin.web.struts2.SimpleActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-5-20
 * Time: 下午8:51
 * To change this template use File | Settings | File Templates.
 */
@Namespace("/base/dxpz")
public class DxpzAction extends SimpleActionSupport {
    private DxpzService dxpzService;
    //短信配置实例
    private Dxpz dxpz;
    //短信配置实例
    private Long dxpzId;
    //名称
    private String mc;
    //分页组件 起始位置
    private int page;
    //分页组件 页面大小
    private int rows = 10;
    //远程ajax验证的值
    private String validateVal;
    //需要远程ajax验证的属性
    private String validateField;

    //短信配置的查询列表显示
    @Action("dxpzList")
    public void dxrzList() {
        this.renderJson(this.dxpzService.findDxpzList(mc, page, rows));
    }

    @Actions({@Action("dxpz_content"),@Action("dxpz_detail")})
    public String dxpzContent() {
        if (dxpzId != null) {
            dxpz = dxpzService.findDxpzDetail(dxpzId);
        }
        return SUCCESS;
    }

    //修改短信配置
    @Action("update_dxpz")
    public void updateDxpz() {
        try {
            this.dxpzService.updateDxpz(dxpz);
            renderText("{\"statusCode\":\"200\", \"message\":\"修改短信配置成功！\", \"operationType\":\"update\"}");
        } catch (RuntimeException e) {
            e.printStackTrace();
            renderText("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    //启用短信配置
    @Action("start_dxpz")
    public void startDxpz() {
        try {
            this.dxpzService.startDxpz(dxpzId);
            renderJson("{\"statusCode\":\"200\", \"message\":\"短信配置启用成功！\", \"operationType\":\"update\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderJson("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }
    
    //停用短信配置
    @Action("stop_dxpz")
    public void stopDxpz() {
        try {
            this.dxpzService.stopDxpz(dxpzId);
            renderJson("{\"statusCode\":\"200\", \"message\":\"短信配置停用成功！\", \"operationType\":\"update\"}");
        } catch (Exception e) {
            e.printStackTrace();
            renderJson("{\"statusCode\":\"300\", \"message\":\"" + e.getMessage() + "\"}");
        }
    }

    //================getter and setter=============

    public Dxpz getDxpz() {
        return dxpz;
    }

    public void setDxpz(Dxpz dxpz) {
        this.dxpz = dxpz;
    }

    public Long getDxpzId() {
        return dxpzId;
    }

    public void setDxpzId(Long dxpzId) {
        this.dxpzId = dxpzId;
    }

    public String getMc() {
        return mc;
    }

    public void setMc(String mc) {
        this.mc = mc;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public String getValidateVal() {
        return validateVal;
    }

    public void setValidateVal(String validateVal) {
        this.validateVal = validateVal;
    }

    public String getValidateField() {
        return validateField;
    }

    public void setValidateField(String validateField) {
        this.validateField = validateField;
    }

    @Autowired
    public void setDxpzService(DxpzService dxpzService) {
        this.dxpzService = dxpzService;
    }
}
